package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.LaboratoryDTO;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.service.LaboratoryService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 实验室数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:17:19
 */
@Api(tags = {"实验室数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/laboratory")
public class LaboratoryController extends BaseController {

    @Resource
    private LaboratoryService laboratoryService;

    @ApiOperation(value = "分页条件查询实验室列表")
    @GetMapping("/page-laboratories")
    public ResultVO<PageInfo<LaboratoryDTO>> pageLaboratories(PageDTO page, LaboratoryDTO laboratoryDTO) {
        PageInfo<LaboratoryDTO> laboratoryPage = laboratoryService.pageLaboratorys(page, laboratoryDTO);
        return ResultVOUtil.success(laboratoryPage);
    }

    @ApiOperation(value = "条件查询实验室列表")
    @GetMapping("/list-laboratories")
    public ResultVO<List<LaboratoryDTO>> listLaboratories(LaboratoryDTO laboratoryDTO) {
        List<LaboratoryDTO> laboratoryList = laboratoryService.listLaboratorys(laboratoryDTO);
        return ResultVOUtil.success(laboratoryList);
    }

    @ApiOperation(value = "添加实验室")
    @PostMapping("/add-laboratory")
    public ResultVO<LaboratoryDTO> addLaboratory(@Validated @RequestBody LaboratoryDTO laboratoryDTO) {
        laboratoryService.addLaboratory(laboratoryDTO);
        return ResultVOUtil.success("添加实验室成功");
    }

    @ApiOperation(value = "更新实验室")
    @PostMapping("/update-laboratory")
    public ResultVO<LaboratoryDTO> updateLaboratory(@Validated @RequestBody LaboratoryDTO laboratoryDTO) {
        laboratoryService.updateLaboratory(laboratoryDTO);
        return ResultVOUtil.success("更新实验室成功");
    }

    @ApiOperation(value = "删除实验室")
    @DeleteMapping("/delete-laboratory/{id}")
    public ResultVO<LaboratoryDTO> deleteLaboratory(@PathVariable("id") String id) {
        laboratoryService.deleteLaboratoryById(id);
        return ResultVOUtil.success("删除实验室成功");
    }

}

